//
//  JWAlarmClockModel.m
//  SiqiCalendar
//
//  Created by sunjiawen on 2018/4/2.
//  Copyright © 2018年 sjw. All rights reserved.
//

#import "JWAlarmClockModel.h"

@implementation JWAlarmClockModel

+ (NSString *)primaryKey {
    return kAlarmID;
}

- (void)updateAlarmDate:(NSDate *)alarmDate {
    if (self.alarmDate == alarmDate) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"alarmID = %@",self.alarmID].firstObject;
    [realm transactionWithBlock:^{
        alarm.alarmDate = alarmDate;
    }];
}

- (void)updateCalendarId:(NSString *)calendarId {
    if ([self.calendarId isEqualToString:calendarId] ) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"calendarId = %@",self.calendarId].firstObject;
    [realm transactionWithBlock:^{
        alarm.calendarId = calendarId;
    }];
}

- (void)updateRepeat:(bool)repeat {
    if (self.repeat == repeat) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"repeat = %@",self.repeat].firstObject;
    [realm transactionWithBlock:^{
        alarm.repeat = repeat;
    }];
}

- (void)updateToggle:(bool)toggle {
    if (self.toggle == toggle) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"toggle = %@",self.toggle].firstObject;
    [realm transactionWithBlock:^{
        alarm.toggle = toggle;
    }];
}

- (void)updateCreateDate:(NSDate *)createDate {
    if (self.createDate == createDate) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"createDate = %@",self.createDate].firstObject;
    [realm transactionWithBlock:^{
        alarm.createDate = createDate;
    }];
}

- (void)updateRepeatTurnName:(NSString *)repeatTurnName {
    if ([self.repeatTurnName isEqualToString:repeatTurnName] ) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"repeatTurnName = %@",self.repeatTurnName].firstObject;
    [realm transactionWithBlock:^{
        alarm.repeatTurnName = repeatTurnName;
    }];
}

- (void)updateAlarmSoundFileName:(NSString *)alarmSoundFileName {
    if ([self.alarmSoundFileName isEqualToString:alarmSoundFileName] ) return;
    RLMRealm *realm = RLMRealm.defaultRealm;
    JWAlarmClockModel *alarm = [JWAlarmClockModel objectsWhere:@"alarmSoundFileName = %@",self.alarmSoundFileName].firstObject;
    [realm transactionWithBlock:^{
        alarm.repeatTurnName = alarmSoundFileName;
    }];
}

@end
